
{{--/**--}}
 {{--* Created by PhpStorm.--}}
 {{--* User: Administrator--}}
 {{--* Date: 2017/3/14--}}
 {{--* Time: 14:09--}}
 {{--**/--}}
@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            知识库分类
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Knowledge Category</a></li>
            <li class="active">Knowledge Category List</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">内容</h3>
                        <span style="float:right;color: #bbb">共{{$count}}条结果</span>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>权重</th>
                                <th>创建时间</th>
                                <th>名称</th>
                                <th>图标</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($knowledgeCategory as $kc)
                                <tr>
                                    <td>{{ $kc['id'] }}</td>
                                    <td>{{ $kc['rank'] }}</td>
                                    <td>{{ $kc['create_time'] }}</td>
                                    <td>{{ $kc['name'] }}</td>
                                    <td><img src="http://vipyipoint.oss-cn-beijing.aliyuncs.com/{{ $kc['icon'] }}" width="100px" height="100px"></td>
                                    <td>
                                        @if($kc['status'] == 1)<label>启用</label>
                                        @else<label>禁用</label>
                                        @endif
                                    </td>
                                    <td>
                                        <a class="btn btn-primary btn-xs"  href="{{ url('knowledgeCategory/knowledgeCategoryEdit/'.$kc['id']) }}">编辑<a>

                                                        @if($kc['status'] == 1)
                                                            <a class="btn btn-warning btn-xs" href="javascript:knowledgeCategoryStatus('{{ $kc['id'] }}',0)">禁用<a>
                                                                    @elseif($kc['status'] == 0)
                                                                        <a class="btn btn-success btn-xs" href="javascript:knowledgeCategoryStatus('{{ $kc['id'] }}',1)">启用<a>
                                        @endif
                                                                                <a class="btn btn-danger btn-xs" href="javascript:delKnowledgeCategory({{ $kc['id'] }})">删除<a>
                                    <td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div calss="pages" style="text-align: center;">
                        {{ $knowledgeCategory->appends(['count'=>$count])->links() }}
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
@stop
@section('script')
    <script>
        function delKnowledgeCategory(id) {
            layer.confirm('删除后不可恢复，是否继续?', {
                btn:['确定','取消']
            },function() {
                $.ajax({
                    url: '/knowledgeCategory/knowledgeCategoryDelete',
                    type: "GET",
                    data: {id:id},
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                        if(res.code == 100) {
                            window.location.href = "knowledgeCategory";
                            layer.msg(res.msg)
                        }
                        else {
                            layer.msg(res.msg)
                        }
                    }
                });
            });
        }

        //禁用,启用
        function knowledgeCategoryStatus(id,status) {
            $.ajax({
                url: '/knowledgeCategory/knowledgeCategoryStatus',
                type: "GET",
                data: {id:id,status:status},
                dataType: "json",
                success: function(res) {
                    console.log(res);
                    if(res.code == 100) {
                        window.location.href=window.location.href;
                        layer.msg(res.msg, {time:1500, icon:6})
                    }
                    else {
                        layer.msg(res.msg, {time:1500, icon:5});
                    }
                }
            });
        }
    </script>
@stop